package model.system;

import model.Observable;
import model.os.Page;
import controller.Main;

public class RAM extends Observable {
	
	private Page[] pageFrames;
	
	private int pointer;
	
	private int lastLocation;
	
	public RAM() {
		pageFrames = new Page[Main.RAM_SIZE];
	}
	
	public int add(Page page) {
		add(page, pointer);
		return pointer++;
	}
	
	public void add(Page page, int location){
		setLastLocation(location);
		pageFrames[location] = page;
		notifyObservers();
	}
	
	public int size() {
		return Main.RAM_SIZE;
	}
	
	public Page getFrame(int location) {
		return pageFrames[location];
	}
	
	public boolean isFull() {
		return pointer == Main.RAM_SIZE;
	}

	public void setPageFrames(Page[] pageFrames) {
		this.pageFrames = pageFrames;
	}

	public Page[] getPageFrames() {
		return pageFrames;
	}

	public void setLastLocation(int lastLocation) {
		this.lastLocation = lastLocation;
	}

	public int getLastLocation() {
		return lastLocation;
	}
	
	public void clear(){
		pageFrames = new Page[Main.RAM_SIZE];
	}
	
	
}
